#include <iostream>
using namespace std;

int TransformMatrix (int *Matrix, int ScaleFactor)
{
	int n = 0;
	int k = 0;
	int TransformCoeffs[4][4] = 
	{
		{1, 1, 1, 1},
		{1, 1,-1,-1},
		{1,-1,-1, 1},
		{1,-1, 1,-1}
	};
	int nTemp[4][4];

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			k = 0;
			for (int n = 0; n < 4; n++)
			{
				 k = k + TransformCoeffs[i][n] * (*(Matrix + (n * 4) + j));
			}
			nTemp[i][j] = k;
		}
	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			k = 0;
			for (int n = 0; n < 4; n++)
			{
				 k = k + (nTemp[i][n] * TransformCoeffs[n][j]);
			}
			*(Matrix + (i * 4) + j) = k >> ScaleFactor;
		}
	}
return 1;
}
int main (int nVars, char* szVars[])
{
	int Matrix[4][4];
	
	for (int i = 0;i<4;i++)
	{
		for (int j = 0; j < 4; j++)
		{
			Matrix[i][j] = 0xFF + 0x4 * i - j;
		}
	}
	for (int i = 0;i<4;i++)
	{
		for (int j = 0; j < 4; j++)
		{
			cout << Matrix[i][j] << "; ";
		}
		cout << "\n";
	}
	cout << "\n";

	TransformMatrix (&Matrix[0][0], 0);

	for (int i = 0;i<4;i++)
	{
		for (int j = 0; j < 4; j++)
		{
			cout << Matrix[i][j] << "; ";
		}
		cout << "\n";
	}
	cout << "\n";

	int aI[16] = {0,1,0,0,1,2,3,2,1,0,1,2,3,3,2,3};
	int aJ[16] = {0,0,1,2,1,0,0,1,2,3,3,2,1,2,3,3};
	for (int i = 0; i < 16; i++)
		cout << Matrix[aI[i]][aJ[i]] << "; ";

	cout << "\n\n";

	TransformMatrix (&Matrix[0][0], 4);

	for (int i = 0;i < 4;i++)
	{
		for (int j = 0; j < 4; j++)
		{
			cout << Matrix[i][j] << "; ";
		}
		cout << "\n";
	}
	return 0;
}
